<template>
  <div class="siderbar-inner" :class="{'close':getSystemConfig.isCollapse}">
    <!-- 用户信息 -->
    <div class="user-detail">
      <!-- 用户头像 -->
      <div class="user-thumb">
        <img :src="getUserInfo.avatar" alt />
      </div>
      <!-- <div class="user-info"></div> -->
      <div class="user-info">
        <el-dropdown>
          <span class="el-dropdown-link">
            <span class="account">
              {{getUserInfo.account}}
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <span class="role">( {{getUserInfo.role}} )</span>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>个人信息</el-dropdown-item>
            <el-dropdown-item>操作记录</el-dropdown-item>
            <el-dropdown-item @click.native="logoutEvent()">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <!-- 导航 -->
    <div class="siderbar-nav">
      <el-menu
      default-active="1-4-1"
      class="el-menu-vertical-demo"
      :collapse="getSystemConfig.isCollapse"
      :backgroundColor="getSystemConfig.theme"
    >
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-s-order"></i>
          <span slot="title">订单管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="1-1">
            <a href>全部订单</a>
          </el-menu-item>
          <el-menu-item index="1-2">
            <a href>待发货</a>
          </el-menu-item>
          <el-menu-item index="1-3">
            <a href>已发货</a>
          </el-menu-item>
           <el-menu-item index="1-4">
            <a href>待收货</a>
          </el-menu-item>
           <el-menu-item index="1-5">
            <a href>已收货</a>
          </el-menu-item>
           <el-menu-item index="1-3">
            <a href>已关闭</a>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-shopping-bag-2"></i>
          <span slot="title">商品管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="1-1">
            <a href>商品列表</a>
          </el-menu-item>
          <el-menu-item index="1-2">
            <a href>商品分类</a>
          </el-menu-item>
          <el-menu-item index="1-3">
            <a href>商品属性</a>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-submenu index="3">
        <template slot="title">
          <i class="el-icon-s-custom"></i>
          <span slot="title">会员管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="1-1">
            <a href>用户列表</a>
          </el-menu-item>
          <el-menu-item index="1-2">
            <a href>等级管理</a>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
       <el-submenu index="4">
        <template slot="title">
          <i class="el-icon-shopping-cart-2"></i>
          <span slot="title">用户购物车</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="1-1">
            <a href>购物车列表</a>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      <el-submenu index="5">
        <template slot="title">
          <i class="el-icon-s-shop"></i>
          <span slot="title">小程序商城管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="1-1">
            <a href>首页轮播图</a>
          </el-menu-item>
          <el-menu-item index="1-2">
            <a href>公告管理</a>
          </el-menu-item>
          <el-menu-item index="1-3">
            <a href>商品分类管理</a>
          </el-menu-item>
           <el-menu-item index="1-4">
            <a href>广告管理</a>
          </el-menu-item>
           <el-menu-item index="1-5">
            <a href>商城主题管理</a>
          </el-menu-item>
            <el-menu-item index="1-6">
            <a href>运费模板管理</a>
          </el-menu-item>
        </el-menu-item-group>
        
      </el-submenu>
      <el-submenu index="6">
        <template slot="title">
          <i class="el-icon-s-tools"></i>
          <span slot="title">系统管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item index="1-1">
            <a href>后台账号管理</a>
          </el-menu-item>
          <el-menu-item index="1-2">
            <a href>角色管理</a>
          </el-menu-item>
          <el-menu-item index="1-3">
            <a href>权限管理</a>
          </el-menu-item>
           <el-menu-item index="1-3">
            <a href>客服管理</a>
          </el-menu-item>
          <el-menu-item index="1-3">
            <a href>前端路由表管理</a>
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
    </div>
  </div>
</template>

<script>
import { mapGetters , mapActions } from "vuex";
export default {
  name: "SiderBar",
  data(){
    return {
     
    }
  },
  computed: {
    ...mapGetters("user", ["getUserInfo"]),
    ...mapGetters("system", ["getSystemConfig"])
  },
  methods:{
    ...mapActions('user',[
      'logout'
    ]),
     logoutEvent(){
      //  console.log('正在退出...');
       this.$http.logout().then((res)=>{
         if(res && res.data.code ==200){
           //退出登录成功 (服务器已经将当前的令牌销毁)
          //  1. 将本地的token 删除 2.跳转到登录页
            this.logout().then(()=>{
              this.$message({
                type:'success',
                message:'您已经成功退出登录！'
              })
               //重新定向到登录页
               this.$router.push('/login');
            })
         }
       })
     }
  }
};
</script>

<style scoped lang="less">
.siderbar-inner {
  width: 200px;
  height: 100vh;
  transition: width 0.35s;
  .user-detail {
    .user-thumb {
      width: 80px;
      height: 80px;
      background: red;
      margin: 10px auto;
      border-radius: 50%;
      overflow: hidden;
      box-shadow:0 0 0px 3px rgba(255,255,255,0.5);
      cursor: pointer;
      img {
        display: block;
        width: 100%;
        height: 100%;
      }
    }
    .user-info {
      text-align: center;
       font-weight: 600;
      padding: 0 3px;
      white-space: nowrap;
      text-overflow: ellipsis;
      .account {
        font-size: 18px;
        text-transform: capitalize;
      }
      .role {
        display: block;
        font-size: 12px;
        line-height: 30px;
        color: #ccc;
      }

      overflow: hidden;
      .el-dropdown {
        color: #f1f1f1;
      }
    }
    &::after {
      content: "";
      display: block;
      width: 80%;
      height: 0.5px;
      margin: 0px auto 10px auto;
      background-color: rgba(255, 255, 255, 0.2);
    }
  }

  .siderbar-nav{
    height: calc(100vh - 160px);
    overflow: auto;
    padding-bottom: 20px;
  }
   .el-menu {
    border: none;
    /deep/.el-submenu__title {
      height: 40px;
      line-height: 40px;
      span {
        color: #ccc;
        font-weight: bold;
      }
      i {
        color: #ccc;
      }
    }
    .el-menu-item-group {
      li {
        text-indent: 20px;
      }
    }
    .el-submenu {
      .el-submenu__title {
        height: 40px;
        line-height: 40px;
      }
      .el-menu-item {
        height: 40px;
        line-height: 40px;
        a {
          color: #ccc;
          font-weight: bold;
        }
      }
      /deep/.el-menu-item-group__title {
        padding: 0;
      }
    }
  }
}

.siderbar-inner.close {
  width: 64px;
  .user-detail {
    position: relative;
    .user-thumb {
      width: 50px;
      height: 50px;
      margin: 10px auto;
      box-shadow:0 0 0px 2px rgba(255,255,255,0.5);
    }
    .user-info {
      .el-dropdown{
        position: absolute;
        top: 0px;
        left: 0;
        width: 100%;
        cursor: pointer;
        .el-dropdown-link{
          display: block;
          height: 50px;
        }
      }
      .account {
        font-size: 0px;
      }
      .role {
        font-size: 0px;
      }

      overflow: hidden;
      .el-dropdown {
        color: #f1f1f1;
      }
    }
    &::after {
      width: 70%;
    }
  }
}

</style>